
import {LGXEnums} from '../../common/sysenum.js'
var dirModeEnums = LGXEnums.LGXRadialGradientDirMode;
import { CoordTRFUtil } from '../../common/tools/coordtool.js'
import lgxcom from '../../common/common.js'
import utilfuncs from '../../common/tools/utilfuncs.js';
var funcs = utilfuncs.UtilFuncs;


var RadialGradientUtil = {}

RadialGradientUtil.getGradientCoord = function (dirMode, graph, mapinfo, isPaintSybolUnitFlag) {
    let poslist = null;
    let mtx = graph.getLocalMatrix();
    let localRect = graph.getLocalZone();
    if (isPaintSybolUnitFlag) {
        localRect = graph.getZone();
    }

    switch (dirMode) {
        case dirModeEnums.fromCenter:
            poslist = this.fromCenter(localRect);
            break;

        case dirModeEnums.fromLeftTop:
            poslist = this.fromLeftTop(localRect);
            break;

        case dirModeEnums.fromRightTop:
            poslist = this.fromRightTop(localRect);
            break;

        case dirModeEnums.fromRightBottom:
            poslist = this.fromRightBottom(localRect);
            break;

        case dirModeEnums.fromLeftBottom:
            poslist = this.fromLeftBottom(localRect);
            break;
    }

    let screenPtLst = null;
    if (poslist && poslist.length > 1) {
        screenPtLst = [];
        if (isPaintSybolUnitFlag) {
            let scaling = mapinfo.getScaling();
            for (let i = 0; i < poslist.length; i++) {
                let pt = poslist[i];
                let x = pt.x * scaling;
                let y = -pt.y * scaling;
                let screenPt = { x, y };
                screenPtLst.push(screenPt);
            }
        }
        else {
            for (let i = 0; i < poslist.length; i++) {
                let pt = poslist[i];
                let worldPt = mtx.MultT(pt);//求相对于控制图形局部坐标系的局部坐标  
                var screenPt = CoordTRFUtil.world2Screen(worldPt, mapinfo);
                screenPtLst.push(screenPt);
            }
        }
    }

    return screenPtLst;
}

RadialGradientUtil.fromCenter = function (localRect) {
    let cntPt = localRect.getCnt();
    let p1 = { x: cntPt.x, y: cntPt.y, z: 0 };
    let R = Math.max(localRect.width(), localRect.height()) / 2.0;
    let p2 = { x: p1.x, y: p1.y + R, z: 0 };
    let ptlst = [];
    ptlst.push(p1);
    ptlst.push(p2);
    return ptlst;
}

RadialGradientUtil.fromLeftTop = function (localRect) {
    let p1 = { x: localRect.left, y: localRect.top, z: 0 };
    let p2 = { x: localRect.right, y: localRect.bottom, z: 0 };
    let R = funcs.distancePoint(p1, p2, 1);
    let ptlst = [];
    ptlst.push(p1);
    let endpt = { x: p1.x, y: p1.y + R, z: 0 };
    ptlst.push(endpt);
    return ptlst;
}

RadialGradientUtil.fromRightTop = function (localRect) {
    let p1 = { x: localRect.right, y: localRect.top, z: 0 };
    let p2 = { x: localRect.left, y: localRect.bottom, z: 0 };
    let R = funcs.distancePoint(p1, p2, 1);
    let ptlst = [];
    ptlst.push(p1);
    let endpt = { x: p1.x, y: p1.y + R, z: 0 };
    ptlst.push(endpt);
    return ptlst;
}



RadialGradientUtil.fromRightBottom = function (localRect) {
    let p1 = { x: localRect.right, y: localRect.bottom, z: 0 };
    let p2 = { x: localRect.left, y: localRect.top, z: 0 };
    let R = funcs.distancePoint(p1, p2, 1);
    let ptlst = [];
    ptlst.push(p1);
    let endpt = { x: p1.x, y: p1.y + R, z: 0 };
    ptlst.push(endpt);
    return ptlst;
}



RadialGradientUtil.fromLeftBottom = function (localRect) {
    let p1 = { x: localRect.left, y: localRect.bottom, z: 0 };
    let p2 = { x: localRect.right, y: localRect.top, z: 0 };
    let R = funcs.distancePoint(p1, p2, 1);
    let ptlst = [];
    ptlst.push(p1);
    let endpt = { x: p1.x, y: p1.y + R, z: 0 };
    ptlst.push(endpt);
    return ptlst;
}

export default { RadialGradientUtil }
